<?php

	//Getting data for dropdown 'sendto'
	include("scripts/dbconnect.php");
	//$query = "SELECT PeId,Username FROM `Person`";
	$query = "SELECT PeId,Username
		FROM Person
		WHERE PeId IN (
			SELECT Contacts.ContactPeId
			FROM Person
			LEFT JOIN (
				Contacts
			) ON ( Contacts.OwnerPeId = Person.PeId )
			WHERE Person.PeId ='".$_SESSION['PeId']."'
				AND Contacts.Approved = '1'
		)";
	$exec = $db->query($query);

	//writing the dropdown
	echo "<label for='receiver' style='font-weight:bold;'>To</label><br />";
	echo "<select id='receiver' name='receiver' >";
		while($row = mysqli_fetch_array($exec)){
			echo "<option value=".$row['PeId'].">".$row['Username']."</option>";
		}
	echo "</select>";

?>
